package com.heitian.ssm.utils;

/**
 * 返回结果的类
 */
public class Result {
    public static final int SUCCESS = 1;
    public static final int FAILURE = -1;

    private static final long serialVersionUID = 5576237395711742681L;

    private String code = "0000";

    private boolean success = false;

    private String msg = "";

    private Object data = null;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {

        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public  void setCode(String code) {
        this.code = code;
    }

    public static Result successReturn(Object data){
        Result result = new Result();
        result.setSuccess(true);
        result.setMsg("返回成功");
        result.setCode("F_000000");
        result.setData(data);
        return result;
    }
    public static Result falseReturnData(Object data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode("F_999999");
        result.setData(data);
        return result;
    }

    public static Result falseReturnCodeMsg(String code, String msg){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    public static Result customReturn(boolean success, String code, String msg, Object data){
        Result result = new Result();
        result.setSuccess(success);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code='" + code + '\'' +
                ", success=" + success +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
